 package server.console.groups.datamanage;


import com.alee.laf.rootpane.WebFrame;
import com.fasterxml.jackson.core.JsonProcessingException;
import server.MapleItemInformationProvider;
import server.life.MapleLifeFactory;
import server.life.MapleMonsterInformationProvider;
import server.life.MonsterDropEntry;
import server.life.MonsterGlobalDropEntry;
import tools.Pair;

import javax.swing.table.DefaultTableModel;
import java.util.*;
import java.util.stream.Collectors;















 public class DropPane extends TabbedPane {
/*  18 */   private final Map<Integer, List<MonsterDropEntry>> allDrop = new TreeMap<>();
/*  19 */   private final Map<String, Pair<Boolean, DefaultTableModel>> modelMap = new LinkedHashMap<>();
/*  20 */   private final Map<String, List<Pair<DataMamageMode, Vector<String>>>> changelist = new LinkedHashMap<>();

   DropPane(WebFrame owner) {
/*  23 */     super(owner);
   }


   void init() {
/*  28 */     this.idTableName.add("怪物ID");
/*  29 */     this.idTableName.add("怪物名称");

/*  31 */     this.dataTableName.add("物品ID");
/*  32 */     this.dataTableName.add("物品名称");
/*  33 */     this.dataTableName.add("最小掉落数量");
/*  34 */     this.dataTableName.add("最大掉落数量");
/*  35 */     this.dataTableName.add("关联任务ID");
/*  36 */     this.dataTableName.add("爆率(百分比)");

    MapleMonsterInformationProvider.getInstance().getAllDrop().entrySet()
            .parallelStream()
            .forEach(i -> allDrop.put(i.getKey(), i.getValue().parallelStream().filter(m -> m.itemId != 0).collect(Collectors.toList())));


/*  42 */     Vector<Vector<String>> alldata = new Vector<>(), normaldata = new Vector<>(), bossdata = new Vector<>(), globaldata = new Vector<>();


/*  45 */     for (Integer mobid : this.allDrop.keySet()) {
/*  46 */       Vector<String> data = new Vector<>();
/*  47 */       data.add(mobid.toString());
/*  48 */       data.add(MapleLifeFactory.getMonsterName(mobid.intValue()));
/*  49 */       if (MapleLifeFactory.isBoss(mobid.intValue())) {
/*  50 */         bossdata.add(data);
       } else {
/*  52 */         normaldata.add(data);
       }
/*  54 */       alldata.add(data);
     }


/*  58 */     for (MonsterGlobalDropEntry entry : MapleMonsterInformationProvider.getInstance().getGlobalDrop()) {
/*  59 */       Vector<String> data = new Vector<>();
/*  60 */       data.add(String.valueOf(entry.itemId));
/*  61 */       data.add(MapleItemInformationProvider.getInstance().getName(entry.itemId));
/*  62 */       data.add(String.valueOf(entry.Minimum));
/*  63 */       data.add(String.valueOf(entry.Maximum));
/*  64 */       data.add(String.valueOf(entry.questid));
/*  65 */       data.add(((entry.chance == 0) ? "0" : String.valueOf(entry.chance / 10000.0D)) + "%");
/*  66 */       globaldata.add(data);
     }

/*  69 */     this.modelMap.put("全部怪物", new Pair(Boolean.valueOf(true), new DefaultTableModel(alldata, this.idTableName)));
/*  70 */     this.modelMap.put("普通怪物", new Pair(Boolean.valueOf(true), new DefaultTableModel(normaldata, this.idTableName)));
/*  71 */     this.modelMap.put("BOSS", new Pair(Boolean.valueOf(true), new DefaultTableModel(bossdata, this.idTableName)));
/*  72 */     this.modelMap.put("全局爆率", new Pair(Boolean.valueOf(false), new DefaultTableModel(globaldata, this.dataTableName)));
   }


   String getTitle() {
/*  77 */     return "怪物爆率";
   }


   protected DefaultTableModel getIDTableModel() {
/*  82 */     return (DefaultTableModel)((Pair)this.modelMap.get("全部怪物")).getRight();
   }


   protected Map<String, Pair<Boolean, DefaultTableModel>> getMultiIDTableModel() {
/*  87 */     return this.modelMap;
   }


   protected DefaultTableModel getDataTableModel() {
/*  92 */     Vector<Vector<String>> datas = new Vector<>();
/*  93 */     if (this.idTable.getSelectedRow() > -1) {
/*  94 */       String id = (String)this.idTable.getValueAt(this.idTable.getSelectedRow(), 0);
/*  95 */       if (this.allDrop.containsKey(Integer.valueOf(id))) {
/*  96 */         for (MonsterDropEntry entry : this.allDrop.get(Integer.valueOf(id))) {
/*  97 */           Vector<String> data = new Vector<>();
/*  98 */           data.add(String.valueOf(entry.itemId));
/*  99 */           data.add((entry.itemId == 0) ? "金币" : MapleItemInformationProvider.getInstance().getName(entry.itemId));
/* 100 */           data.add(String.valueOf(entry.minimum));
/* 101 */           data.add(String.valueOf(entry.maximum));
/* 102 */           data.add(String.valueOf(entry.questid));
/* 103 */           data.add(((entry.chance == 0) ? "0" : String.valueOf(entry.chance / 10000.0D)) + "%");
/* 104 */           datas.add(data);
         }
       }
     }
/* 108 */     return new DefaultTableModel(datas, this.dataTableName);
   }


   protected Vector<String> getDefaultDataVector() {
/* 113 */     Vector<String> ret = new Vector<>();
/* 114 */     ret.add("");
/* 115 */     ret.add("");
/* 116 */     ret.add("1");
/* 117 */     ret.add("1");
/* 118 */     ret.add("0");
/* 119 */     ret.add("0%");
/* 120 */     return ret;
   }


   protected String getIDName(String id) {
     try {
/* 126 */       return MapleLifeFactory.getMonsterName(Integer.valueOf(id).intValue());
/* 127 */     } catch (NumberFormatException e) {
/* 128 */       return null;
     }
   }


   protected String getDataName(String id) {
     try {
/* 135 */       return MapleItemInformationProvider.getInstance().getName(Integer.valueOf(id).intValue());
/* 136 */     } catch (NumberFormatException e) {
/* 137 */       return null;
     }
   }


   protected void addToChangeList(DataMamageMode mode, String id, Vector<String> row) {
     List<Pair<DataMamageMode, Vector<String>>> oldrow;
/* 144 */     if (this.changelist.containsKey(id)) {
/* 145 */       oldrow = this.changelist.get(id);
     } else {
/* 147 */       oldrow = new LinkedList<>();
     }
/* 149 */     oldrow.add(new Pair(mode, row));
/* 150 */     this.changelist.put(id, oldrow);
/* 151 */     this.button_apply.setEnabled(true);
   }


   protected void applyChange(boolean change) {
/* 156 */     if (!this.changelist.isEmpty())

       try {

/* 160 */         for (Map.Entry<String, List<Pair<DataMamageMode, Vector<String>>>> entry : this.changelist.entrySet()) {
/* 161 */           String mobid = entry.getKey();
/* 162 */           for (Pair<DataMamageMode, Vector<String>> pair : entry.getValue()) {
/* 163 */             MonsterDropEntry monsterDropEntry; DataMamageMode mode = (DataMamageMode)pair.getLeft();
/* 164 */             Vector<String> row = (Vector<String>)pair.getRight();
/* 165 */             List<MonsterDropEntry> monsterDropEntries = null;
/* 166 */             switch (mode) {
               case ID_编辑:
               case ID_删除:
/* 169 */                 if (!this.allDrop.containsKey(Integer.valueOf(mobid))) {
/* 170 */                   monsterDropEntries = Collections.emptyList();
/* 171 */                   this.allDrop.put(Integer.valueOf(mobid), monsterDropEntries); break;
                 }
/* 173 */                 this.allDrop.remove(Integer.valueOf(mobid));
                 break;

               case DATA_编辑:
/* 177 */                 if (row.size() != this.dataTableName.size()) {
/* 178 */                   throw new RuntimeException("Drop row index error");
                 }





/* 185 */                 monsterDropEntry = new MonsterDropEntry(Integer.valueOf(row.get(0)).intValue(), (int)(Double.valueOf(((String)row.get(5)).substring(0, ((String)row.get(5)).length() - 1)).doubleValue() * 10000.0D), Integer.valueOf(row.get(2)).intValue(), Integer.valueOf(row.get(3)).intValue(), Integer.valueOf(row.get(4)).intValue());
/* 186 */                 if (this.allDrop.containsKey(Integer.valueOf(mobid))) {
/* 187 */                   monsterDropEntries = this.allDrop.get(Integer.valueOf(mobid));
/* 188 */                   monsterDropEntries.removeIf(monsterDropEntry1 -> (monsterDropEntry1.itemId == monsterDropEntry.itemId));
/* 189 */                   monsterDropEntries.add(monsterDropEntry); break;
                 }
/* 191 */                 monsterDropEntries = Collections.singletonList(monsterDropEntry);
/* 192 */                 this.allDrop.put(Integer.valueOf(mobid), monsterDropEntries);
                 break;

               case DATA_删除:
/* 196 */                 if (this.allDrop.containsKey(Integer.valueOf(mobid))) {
/* 197 */                   monsterDropEntries = this.allDrop.get(Integer.valueOf(mobid));
/* 198 */                   monsterDropEntries.removeIf(monsterDropEntry1 -> 
/* 199 */                       (monsterDropEntry1.itemId == Integer.valueOf(row.get(0)).intValue() && monsterDropEntry1.minimum == Integer.valueOf(row.get(2)).intValue() && monsterDropEntry1.maximum == Integer.valueOf(row.get(3)).intValue() && monsterDropEntry1.questid == Integer.valueOf(row.get(4)).intValue() && monsterDropEntry1.chance == Double.valueOf(((String)row.get(5)).substring(0, ((String)row.get(5)).length() - 1)).doubleValue() * 10000.0D));
                 }
                 break;
             }




/* 207 */             if (monsterDropEntries == null) {
/* 208 */               MapleMonsterInformationProvider.getInstance().removeDropData(Integer.parseInt(mobid)); continue;
             }
/* 210 */             MapleMonsterInformationProvider.getInstance().setDropData(mobid, monsterDropEntries);
           }

         }

/* 215 */       } catch (JsonProcessingException e) {
/* 216 */         e.printStackTrace();
       } finally {
/* 218 */         this.changelist.clear();
       }
   }
 }


/* Location:              C:\PGX\Server.jar!\server\console\groups\datamanage\DropPane.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */